using Newtonsoft.Json;
using System;

namespace Ganweisoft.IoTCenter.Module.MediaPlatform.Utilities
{
    [Serializable]
    public class ApiResult
    {
        public bool IsSuccessed { get; set; }
        [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
        public string Code { get; set; }
        [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
        public string Message { get; set; }
        [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
        public string StackTrace { get; set; }
        public static ApiResult Success { get; } = new ApiResult { IsSuccessed = true };
        public static ApiResult Failed(string code, string message, string stackTrace = "")
        {
            return new ApiResult
            {
                IsSuccessed = false,
                Code = code,
                Message = message,
                StackTrace = stackTrace
            };
        }

        public static ApiResult<T> Failed<T>(string code, string message, string stackTrace = null)
        {
            return new ApiResult<T>
            {
                IsSuccessed = false,
                Code = code,
                Message = message,
                StackTrace = stackTrace
            };
        }

        public static ApiResult<T> Successed<T>(T data)
        {
            return new ApiResult<T>
            {
                IsSuccessed = true,
                Data = data
            };
        }

        public ApiResult() { }
        public ApiResult(string code, string message, string stackTrace = "")
        {
            Code = code;
            Message = message;
            StackTrace = stackTrace;
        }
    }

    [Serializable]
    public class ApiResult<T> : ApiResult
    {
        public T Data { get; set; }
    }
}
